package com.company.company.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author dfj@99chuxing.com
 * @date 2018/4/16 0016 15:30
 */
@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;


    /** 开始熔断器功能，服务不可用时调用 fallbackMethod */
    @HystrixCommand(fallbackMethod ="fallbackMethod" )
    public String hiService() {
        return restTemplate.getForObject("http://person/demo",String.class);
    }



    /** 服务不可用时回调方法 */
    public String fallbackMethod() {
        return "sorry,service is open Error";
    }
}
